home *** CD-ROM | disk | FTP | other *** search
- (*===========================================================================*)
- (* Copy message *)
- (* Make Carbon Copies *)
- (* *)
- (* Copyright 1988, 1989, 1990, 1991, 1992 by H. Roy Engehausen. All *)
- (* rights reserved. *)
- (* *)
- (*===========================================================================*)
-
- {$O+}
-
- {$UNDEF DEBUG_DIST} (* Debug processing messages with a dist list *)
-
- UNIT BBCMSG;
-
- INTERFACE
-
- USES
- CRT,
- bbcopy,
- bbdummy,
- bbmdata,
- bbmess,
- bbmf,
- bbmisc,
- bbmisc2,
- bbsdata,
- bbsto,
- bbstr,
- bbtask;
-
- PROCEDURE copy_msg(m_num : WORD;
- to_addr : STRING;
- tell_user : BOOLEAN;
- assign_new_bid : BOOLEAN);
-
- PROCEDURE make_cc;
-
- IMPLEMENTATION
-
- (*===========================================================================*)
- (* Copy message *)
- (*===========================================================================*)
-
-
- PROCEDURE copy_msg(m_num : WORD;
- to_addr : STRING;
- tell_user : BOOLEAN;
- assign_new_bid : BOOLEAN);
-
- VAR
- msg_ptr : msg_index_ptr;
- f_str : file_name_str;
- t_str : file_name_str;
- w_str : STRING;
-
- BEGIN
-
- (*-----------------------------------------------------------------------*)
- (* Find the message *)
- (*-----------------------------------------------------------------------*)
-
- msg_ptr := find_msg(m_num);
-
- IF msg_ptr = NIL THEN
- BEGIN;
- send_message(message_rmc_nf);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Set the message data from the old message into the new one *)
- (*-----------------------------------------------------------------------*)
-
- WITH active_tcb^ DO
- curr_msg := msg_ptr^;
-
- (*-----------------------------------------------------------------------*)
- (* Process the "to" data *)
- (*-----------------------------------------------------------------------*)
-
- send_msg_to_process(to_addr);
- IF active_tcb^.error_sw THEN
- EXIT;
-
- (*-----------------------------------------------------------------------*)
- (* Set the new fields *)
- (*-----------------------------------------------------------------------*)
-
- WITH active_tcb^.curr_msg.msg_i_mb DO
- BEGIN;
-
- msg_type := msg_ptr^.msg_i_mb.msg_type;
- msg_flag := 0;
- msg_from := msg_ptr^.msg_i_mb.msg_from;
- msg_from_at := msg_ptr^.msg_i_mb.msg_from_at;
- msg_dt_in := msg_ptr^.msg_i_mb.msg_dt_in;
- msg_dt_orig := msg_ptr^.msg_i_mb.msg_dt_orig;
- msg_no_orig := msg_ptr^.msg_i_mb.msg_no_orig;
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Build the from and to file names *)
- (*-----------------------------------------------------------------------*)
-
- t_str := opt_block.msg_file_dir + active_tcb^.port_chan_s + '.IN';
-
- STR(m_num, f_str);
- f_str := opt_block.msg_file_dir + 'BB' + f_str + '.MSG';
-
- (*-----------------------------------------------------------------------*)
- (* Print the message header in format #1 *)
- (*-----------------------------------------------------------------------*)
-
- IF tell_user THEN
- BEGIN;
- send_msg_header(1);
- send_tnc_data_str(header_msg_block(msg_ptr, 1) + cr);
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Copy the file. Print any error message that appears *)
- (*-----------------------------------------------------------------------*)
-
- w_str := copy_file_binary(f_str, t_str, TRUE);
- IF w_str <> '' THEN
- BEGIN;
- send_tnc_data_str(w_str + cr);
- active_tcb^.error_sw := TRUE;
- EXIT;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Mark new bid *)
- (*-----------------------------------------------------------------------*)
-
- IF assign_new_bid THEN
- BEGIN;
- active_tcb^.curr_msg.msg_i_mb.msg_bid := #1;
- active_tcb^.curr_msg.msg_i_mb.msg_flag :=
- active_tcb^.curr_msg.msg_i_mb.msg_flag OR mf_bid_change;
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Add the message *)
- (*-----------------------------------------------------------------------*)
-
- add_msg(t_str, TRUE);
- make_cc;
-
- (*-----------------------------------------------------------------------*)
- (* Tell user *)
- (*-----------------------------------------------------------------------*)
-
- IF NOT active_tcb^.tcb_abbs THEN
- send_message(message_added_msg);
-
- END;
-
- (*===========================================================================*)
- (* Make multiple copies of a message *)
- (* *)
- (* This should really be part of ADD_MSG but can't because of *)
- (* "CIRCULAR" paths. We use recursiveness to make the copies *)
- (* *)
- (*===========================================================================*)
-
- PROCEDURE make_cc;
-
- VAR
- b : BOOLEAN;
- cc_data : STRING;
- cc_file : TEXT;
- cc_file_name : file_name_str;
- i : BYTE;
- j : BYTE;
- master_msg : WORD;
- master_msg_ptr : msg_index_ptr;
- str_ptr : ^STRING;
- this_act : action_msg_ptr;
- word_data : bb_addr_str;
-
- LABEL
- read_loop;
-
- (*=========================================================================*)
- (* Clean up subroutine *)
- (*=========================================================================*)
-
- PROCEDURE clean_up;
- BEGIN;
-
- active_tcb^.tcb_make_cc := FALSE;
-
- {$I-}
- CLOSE(cc_file);
- {$I+}
-
- END;
-
- (*=========================================================================*)
- (* Open a file *)
- (*=========================================================================*)
-
- FUNCTION open_file : BOOLEAN;
- BEGIN;
-
- (*---------------------------------------------------------------------*)
- (* Find any actions to set a distribution list *)
- (*---------------------------------------------------------------------*)
-
- this_act := NIL;
-
- REPEAT
- msg_action_check(@active_tcb^.curr_msg, this_act);
- UNTIL (this_act = NIL)
- OR ((this_act^.action_type AND action_msg_distr) <> 0);
-
- (*---------------------------------------------------------------------*)
- (* If we found an action then do it *)
- (*---------------------------------------------------------------------*)
-
- IF (this_act <> NIL)
- AND ((this_act^.action_type AND action_msg_invert) = 0) THEN
- BEGIN;
-
- (*-----------------------------------------------------------------*)
- (* Locate the name to use *)
- (*-----------------------------------------------------------------*)
-
- i := LENGTH(this_act^.action_info) + 1;
- str_ptr := ADDR(this_act^.action_info[i]);
-
- cc_file_name := str_ptr^;
-
- END;
-
- (*---------------------------------------------------------------------*)
- (* Build the file name. Truncate the address if necessary *)
- (*---------------------------------------------------------------------*)
-
- IF POS('.', cc_file_name) = 0 THEN
- BEGIN;
- cc_file_name := SUBSTR(cc_file_name, 1, 8);
-
- cc_file_name := opt_block.msg_file_dir + cc_file_name + '.CC';
- END;
-
- (*---------------------------------------------------------------------*)
- (* Open the file for input *)
- (*---------------------------------------------------------------------*)
-
- ASSIGN(cc_file, cc_file_name);
- {$I-}
- RESET(cc_file);
- {$I+}
-
- (*---------------------------------------------------------------------*)
- (* If the open fails then nothing is necessary *)
- (*---------------------------------------------------------------------*)
-
- open_file := IORESULT = 0;
-
- END;
-
- (*=========================================================================*)
- (* Main line *)
- (*=========================================================================*)
-
- BEGIN;
-
- WITH active_tcb^, active_tcb^.curr_msg.msg_i_mb DO
- BEGIN;
-
- (*-------------------------------------------------------------------*)
- (* Prevent loops *)
- (*-------------------------------------------------------------------*)
-
- IF tcb_make_cc THEN
- EXIT;
-
- (*-------------------------------------------------------------------*)
- (* Don't do distribution lists *)
- (*-------------------------------------------------------------------*)
-
- {$IFDEF DEBUG_DIST}
- WRITELN('CC process 2 -- ', (msg_flag AND mf_fwd_list) <> 0);
- {$ENDIF}
-
- IF (msg_flag AND mf_fwd_list) <> 0 THEN
- EXIT;
-
- (*-------------------------------------------------------------------*)
- (* Get the assumed file name *)
- (*-------------------------------------------------------------------*)
-
- cc_file_name := msg_to_at;
- IF (cc_file_name = '') OR (cc_file_name = opt_block.this_bb_sign) THEN
- cc_file_name := msg_to;
-
- (*-------------------------------------------------------------------*)
- (* If we can't open then we are done *)
- (*-------------------------------------------------------------------*)
-
- IF NOT open_file THEN
- EXIT;
-
- (*-------------------------------------------------------------------*)
- (* Show that we are in cc *)
- (*-------------------------------------------------------------------*)
-
- tcb_make_cc := TRUE;
-
- (*-------------------------------------------------------------------*)
- (* Loop making copies *)
- (*-------------------------------------------------------------------*)
-
- master_msg := msg_number;
-
- read_loop:
-
- WHILE (NOT EOF(cc_file)) DO
- BEGIN;
-
- task_switch;
-
- (*---------------------------------------------------------------*)
- (* Read a line and strip blanks *)
- (*---------------------------------------------------------------*)
-
- READLN(cc_file, cc_data);
-
- strip_var(cc_data, 'B');
-
- upcase_str_var(cc_data);
-
- IF comment_line(cc_data) THEN
- GOTO read_loop;
-
- (*---------------------------------------------------------------*)
- (* See if a special statement. If so handle *)
- (*---------------------------------------------------------------*)
-
- word_data := subwordl(cc_data, 1, 8);
-
- IF (word_data = 'OK') OR (word_data = 'NOT_OK') THEN
- IF (NOT verify_auth_list(@cc_data, uid_data.user_id)) OR
- (NOT verify_auth_list(@cc_data,
- curr_msg.msg_i_mb.msg_from)) THEN
- BEGIN;
- clean_up;
- EXIT;
- END
- ELSE
- word_data := '';
-
- (*---------------------------------------------------------------*)
- (* If data exists the process it. A check is made to try to *)
- (* not send the msg back to the originator *)
- (*---------------------------------------------------------------*)
-
- IF (word_data <> '') AND (word_data <> uid_data.user_id)
- AND (word_data <> curr_msg.msg_i_mb.msg_from) THEN
- BEGIN;
-
- i := POS(' NONEW$', cc_data);
- b := i > 0;
-
- IF b THEN
- FOR j := i TO i + 7 DO
- cc_data[j] := ' ';
-
- copy_msg(master_msg, cc_data, FALSE, NOT b);
-
- IF error_sw THEN
- BEGIN;
- clean_up;
- EXIT;
- END;
-
- END;
-
- END; (*----- End read cc list loop --------------------------------*)
-
- END;
-
- (*-----------------------------------------------------------------------*)
- (* Clear up things *)
- (*-----------------------------------------------------------------------*)
-
- clean_up;
-
- (*-----------------------------------------------------------------------*)
- (* Mark the original as done *)
- (*-----------------------------------------------------------------------*)
-
- master_msg_ptr := find_msg(master_msg);
-
- active_tcb^.curr_msg := master_msg_ptr^;
-
- WITH master_msg_ptr^.msg_i_mb DO
- msg_flag := msg_flag OR mf_fwd;
-
- update_msg(master_msg_ptr);
-
- END;
-
- END.